package com.example.demo.Service;

import com.example.demo.Bean.LeavePeople;
import com.example.demo.Bean.LogDate;
import com.example.demo.Bean.People;
import com.example.demo.Mapper.LeavePeopleMapper;
import com.example.demo.Mapper.PeopleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("leavePeopleService")
public class LeavePeopleService {
    @Autowired
    private LeavePeopleMapper leavePeopleMapper;
    @Autowired
    private PeopleMapper peopleMapper;
    @Autowired
    private LogDateService logDateService;

    public List<LeavePeople> selectLeavePeople(){return leavePeopleMapper.selectLeavePeople();}
    public void comeBack(String peopleID){
        LeavePeople leavePeople = leavePeopleMapper.selectOneLeavePeople(peopleID);
        People people = new People();
        people.setPeopleID(peopleID);
        people.setName(leavePeople.getName());
        people.setComeTime(leavePeople.getComeTime());
        people.setFace(leavePeople.getFace());
        people.setId(leavePeople.getId());
        people.setLearn(leavePeople.getLearn());
        people.setOld(leavePeople.getOld());
        people.setNation(leavePeople.getNation());
        people.setMoney(leavePeople.getMoney());
        people.setWork(leavePeople.getWork());
        people.setSex(leavePeople.getSex());

        //添加People
        peopleMapper.insertPeople(people);
        //删除表中原来的LeavePeople
        leavePeopleMapper.deleteOneLeavePeople(peopleID);
        //更新日志
        LogDate log = new LogDate();
        log.setLogID(String.valueOf((System.currentTimeMillis())));
        log.setDate(new Date());
        log.setWay("主动");
        log.setPeopleID(peopleID);
        log.setReason("无");
        log.setType("复职");
        logDateService.insertLogDate(log);

    }
}
